package hk.ust.android_competition.activities;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Point;
import android.media.Image;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.GridLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.Random;

import hk.ust.android_competition.e_pet.R;
import hk.ust.android_competition.event.MiniGame;
import hk.ust.android_competition.pet.Pet;
import hk.ust.android_competition.pet.PetType;
import hk.ust.android_competition.view_adapter.MiniGameViewAdapter;

public class MiniGameActivity extends LandscapeFullScreenActivity implements View.OnClickListener {
    private MiniGame game;
    Bundle extra;
    private MiniGameViewAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        extra = getIntent().getExtras();
        game = new MiniGame();
        adapter = new MiniGameViewAdapter(this, R.layout.activity_mini_game);
        switch (extra.getInt("pet type")) {
            case 0:
                adapter.setPetImage(PetType.Panda);
                break;
            case 1:
                adapter.setPetImage(PetType.Rabbit);
                break;
            case 2:
                adapter.setPetImage(PetType.Giraffe);
                break;
        }
        adapter.updateGameLayout(game);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.position0:
                positionIsTouched(0);
                break;
            case R.id.position1:
                positionIsTouched(1);
                break;
            case R.id.position2:
                positionIsTouched(2);
                break;
            case R.id.position3:
                positionIsTouched(3);
                break;
            case R.id.position4:
                positionIsTouched(4);
                break;
            case R.id.position5:
                positionIsTouched(5);
                break;
            case R.id.position6:
                positionIsTouched(6);
                break;
            case R.id.position7:
                positionIsTouched(7);
                break;
            case R.id.position8:
                positionIsTouched(8);
                break;
            case R.id.game_back:
                finish();
                break;
        }
    }

    private void positionIsTouched(int position) {
        game.playerMove(position);
        adapter.updateGameLayout(game);
    }


}
